home *** CD-ROM | disk | FTP | other *** search
- /* rewind.c, from p. 458 of Turbo C Bible */
- #include <stdio.h>
- main()
- {
- FILE *infile;
- char filename[80], buffer[81];
- printf("Enter name of a test file: ");
- gets(filename);
- /* Open the file for reading */
- if ((infile = fopen(filename, "r")) == NULL)
- {
- printf("fopen failed.\n");
- exit(0);
- }
- /* Read and display a line */
- fgets(buffer, 80, infile);
- printf("Line read (before rewind): %s", buffer);
- /* Rewind and read a line again */
- rewind(infile);
- fgets(buffer, 80, infile);
- printf("Line read (after rewind) : %s", buffer);
- }